﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using Fuse8.DomainFramework.BusinessService;
using Telerik.Web.Mvc;

using Fuse8.ContentManagementFramework.Domain;

namespace Fuse8.ContentManagementFramework.Administration.Controllers
{
    public class CmsMediaContentTagController : CmsAdminController<CmsMediaContentTag>
    {
        public readonly IEntityBusinessService<CmsMediaContentTag, int> _mediaContentTagService = new BusinessServiceFacade<CmsMediaContentTag, int>();

        public ActionResult Index(int? pageSize)
        {
            int currentPageSize = pageSize ?? DefaultPageSize;

            var data = _mediaContentTagService.FindAll();

            ViewBag.PageSize = currentPageSize;
            ViewBag.Total = data.Count();

            return View(data);
        }

        [HttpPost]
        public ActionResult AllTags()
        {
            var data = _mediaContentTagService.FindAll();

            return Json(data);
        }

        [GridAction]
        public ActionResult _Index(int? pageSize)
        {
            var data = _mediaContentTagService.FindAll();

            return View(
                   new GridModel<CmsMediaContentTag>
                   {
                       Data = data
                   });
        }

        protected override bool _AddCategory(string categoryName)
        {
            _mediaContentTagService.Add(
                new CmsMediaContentTag
                {
                    TagName = categoryName
                });

            return true;
        }

        protected override bool _EditCategory(int id, string categoryName)
        {
            _mediaContentTagService.Save(
                new CmsMediaContentTag
                {
                    Id = id,
                    TagName = categoryName
                });

            return true;
        }

        protected override bool _Delete(int id)
        {
            _mediaContentTagService.Remove(
                new CmsMediaContentTag
                {
                    Id = id
                });

            return true;
        }
    }
}
